import axios from 'axios'
import { message } from 'ant-design-vue';

const http = axios.create({
    baseURL: "https://lianghj.top:8888/api/private/v1/",
    // https://lianghj.top:8888/api/private/v1/
    // http://127.0.0.1:8888/api/private/v1/
    timeout: 2000
})

//拦截请求数据
http.interceptors.request.use((config) => {
    //带请求头
    config.headers.Authorization = localStorage.getItem('token')
    return config;
}, (error) => {
    return Promise.reject(error);
});

//拦截响应数据
http.interceptors.response.use((res) => {
    const data = res.data
    if (res.status === 200) {
        return Promise.resolve(data)
    }
}, (err) => {
    message.error(err + "  " + "唔...服务器好像出现了问题")
    return Promise.reject(err)
})

export default http